# 指定编译器最小版本
cmake_minimum_required(VERSION 3.10)

#指定工具链
if (CONFIG_CROSS_COMPILE)
    if (CONFIG_CHIP_F133)
        set(toolchain_file_global "${CMAKE_SOURCE_DIR}/tools/cmake/toolchain_f133.cmake")
    elseif(CONFIG_CHIP_T113S3)
        set(toolchain_file_global "${CMAKE_SOURCE_DIR}/tools/cmake/toolchain_t113s3.cmake")
    elseif(CONFIG_CHIP_F1CX00S)
        set(toolchain_file_global "${CMAKE_SOURCE_DIR}/tools/cmake/toolchain_f1c100.cmake")
    endif()
else()
    set(toolchain_file_global "${CMAKE_SOURCE_DIR}/tools/cmake/toolchain_host.cmake")
endif()

set(CMAKE_TOOLCHAIN_FILE ${toolchain_file_global})

#项目工程名
project(arm_linux_gcc C CXX ASM)
set(TARGET_NAME demo)

set(CMAKE_C_STANDARD 99)

#指定编译平台/架构与语言标准

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

#设置编译优化选项
set(OPTIMIZE_FLAGS -g -Og)

#预处理开关
# add_compile_definitions(__SOFTFP__)

if (CONFIG_FOO)
    message(STATUS "CONFIG_FOO is ON")
endif()

if (CONFIG_FOO1)
    message(STATUS "CONFIG_FOO1 is ON")
endif()

if (CONFIG_FOO2)
    message(STATUS "CONFIG_FOO2 is ON")
endif()



if (CONFIG_FOO4)
    message(STATUS "CONFIG_FOO4 is ON")
endif()

#添加源文件
set(incs 
    "app/inc"
)

set(srcs
    "app/src/main.c"
    "app/src/audio_control.c"
    "app/src/http_client.c"
    "app/src/wifi_connect.c"
    "app/src/tcp_server.c"
    "app/src/msg_queue.c"
)

include_directories(${incs})

# 添加要引用的库的子目录
add_subdirectory(components)

# 添加主目标
add_executable("${TARGET_NAME}" ${srcs})

# 将子组件链接到主目标
set(TARGET_LIBS EasyLogger cJSON webclient)
list(APPEND TARGET_LIBS pthread)

if (CONFIG_ASAN)
    list(APPEND TARGET_LIBS asan)
    set(CMAKE_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer -g")
endif()

target_link_libraries("${TARGET_NAME}" ${TARGET_LIBS})

#添加自定义命令
# add_custom_command(
#     TARGET "${TARGET_NAME}.elf" POST_BUILD
#     COMMAND objcopy -O ihex "${TARGET_NAME}.elf" "${TARGET_NAME}.hex"
#     COMMAND objcopy -I ihex -O binary "${TARGET_NAME}.hex" "${TARGET_NAME}.bin"
# )

